from django.conf import settings
from django.views.generic import TemplateView


class WebMixin(object):
    def __init__(self):
        pass

    def get_template_names(self, *args, **kwargs):
        return 'no_6/{}'.format(self.template_name)
        # t = kwargs.get('template_name') or self.template_name
        # return ['pages/{}'.format(t)]

    @property
    def client_ip(self):
        ip = None
        if hasattr(self, 'request'):
            forwarded_for = self.request.META.get('HTTP_X_FORWARDED_FOR')
            remote_addr = self.request.META.get('REMOTE_ADDR')
            ip = forwarded_for.split(',')[0] if forwarded_for else remote_addr
        return ip


class WebTemplateView(WebMixin, TemplateView):
    def __init__(self):
        super(WebTemplateView, self).__init__()

    # def get(self, request, *args, **kwargs):
    #     if self.lang not in ['en', 'zh-cn', 'ja']:
    #         raise Http404('Language does not exist')
    #     return super(WebTemplateView, self).get(request, *args, **kwargs)

    def get_context_data(self, **kwargs):
        context = super(WebTemplateView, self).get_context_data(**kwargs)
        context['settings'] = settings
        return context


